import { getSelectDataCommon, getSelectDataMapList, getTenantID } from '@/utils';
import { ILoadMapTypeAll } from '@/common';
import { ManageCommonAPI } from '@/pages/type';
import { useContext } from 'react';

/** 采购申请搜索 */
const getSourceSearchList = (loadMdicMapList: Record<string, any>): ManageCommonAPI.ISearchList => {
  /** 采购方式 */
  const businessTypeList = getSelectDataMapList(loadMdicMapList?.[`${getTenantID()}${ILoadMapTypeAll.PURCHASE_METHOD}`], 'name', 'id', true);

  /** 采购类型 */
  const supplyTypeList = getSelectDataMapList(loadMdicMapList?.[`${getTenantID()}${ILoadMapTypeAll.PURCHASE_CATEGORY}`], 'name', 'id', true);

  /** 采购类别 */
  const supplyList = getSelectDataMapList(
    [
      { label: '月度计划', value: 0 },
      { label: '零星采购', value: 1 },
      { label: '实验平台', value: 2 },
    ],
    'label',
    'value',
    true,
  );

  return [
    {
      name: 'projectName',
      placeholder: '采购项目名称',
      label: '采购项目名称',
      componentType: 'Input',
      allowClear: true,
      md: 8,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'procureReal',
      placeholder: '采购方式',
      label: '采购方式',
      componentType: 'TreeSelect',
      allowClear: true,
      md: 8,
      sm: 24,
      whetherSenior: false,
      dataSource: businessTypeList,
      fieldNames: {
        label: 'name',
        value: 'value',
        children: 'children',
      },
    },
    // {
    //   name: 'supplyType',
    //   placeholder: '采购类型',
    //   label: '采购类型',
    //   componentType: 'TreeSelect',
    //   allowClear: true,
    //   md: 8,
    //   sm: 24,
    //   whetherSenior: false,
    //   dataSource: supplyTypeList,
    //   fieldNames: {
    //     label: 'name',
    //     value: 'value',
    //     children: 'children',
    //   },
    // },
    {
      name: 'supplyWay',
      placeholder: '采购类别',
      label: '采购类别',
      componentType: 'Select',
      allowClear: true,
      md: 8,
      sm: 24,
      whetherSenior: false,
      dataSource: supplyList,
    },
  ];
};

/** 范本搜索 */
const getTempalSearchList = (loadMdicMapList: Record<string, any>, queryTypeObj: Record<string, any>): ManageCommonAPI.ISearchList => {
  /** 合同类型 */
  const businessTypeList = getSelectDataMapList(loadMdicMapList?.[`${getTenantID()}${ILoadMapTypeAll.CONTRACT_TYPE}`], 'name', 'id', true);

  return [
    {
      name: 'fullName',
      placeholder: '范本名称',
      label: '范本名称',
      componentType: 'Input',
      allowClear: true,
      md: 8,
      sm: 24,
      whetherSenior: false,
      searchParams: {
        fieldType: 'String',
        fieldParam: 0,
        fieldUse: 0,
        searchType: 0,
        seq: 0,
      },
    },
    {
      name: 'templateInfo',
      placeholder: '范本描述',
      label: '范本描述',
      componentType: 'Input',
      allowClear: true,
      md: 8,
      sm: 24,
      whetherSenior: false,
      searchParams: {
        fieldType: 'String',
        fieldParam: 0,
        fieldUse: 0,
        searchType: 0,
        seq: 0,
      },
    },
    {
      name: 'businessType',
      placeholder: '合同类型可搜索',
      label: '合同类型可搜索',
      componentType: 'QueryParams',
      allowClear: true,
      dataSource: businessTypeList,
      md: 8,
      sm: 24,
      whetherSenior: false,
      fieldNames: { label: 'name', value: 'value', children: 'children' },
      searchParams: {
        fieldType: 'String',
        fieldParam: 1,
        fieldUse: 0,
        searchType: 1,
        seq: 0,
      },
    },

    {
      name: queryTypeObj?.params,
      placeholder: '权限参数',
      label: '权限参数',
      componentType: 'QueryParams',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
      searchParams: {
        fieldType: 'String',
        fieldParam:
          queryTypeObj?.params == 'createDepartmentID'
            ? '5'
            : queryTypeObj?.params == 'createDepartmentID'
            ? '4'
            : queryTypeObj?.params == 'createrID'
            ? '2'
            : '3',
        fieldUse: 0,
        searchType: 2,
        seq: 0,
      },
    },
    {
      name: 'state',
      placeholder: '权限参数-state',
      label: '权限参数-state',
      componentType: 'QueryParams',
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: false,
      searchParams: {
        fieldType: 'String',
        fieldParam: 1,
        fieldUse: 0,
        searchType: 1,
        seq: 0,
      },
    },
  ];
};

/** 合同主体搜索 */
const getSubjectSearchList = (serviceType: boolean): ManageCommonAPI.ISearchList => {
  return [
    {
      name: 'fullName',
      placeholder: serviceType ? '合同主体名称' : '单位名称',
      label: '合同主体名称',
      componentType: 'Input',
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'workAddress',
      placeholder: '单位地址',
      label: '单位地址',
      componentType: 'Input',
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'searchCreditID',
      placeholder: '统一社会信用代码',
      label: '统一社会信用代码',
      componentType: 'Input',
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'registerPhone',
      placeholder: '单位电话',
      label: '单位电话',
      componentType: 'Input',
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: false,
    },
    // {
    //   name: 'contactName',
    //   placeholder: '联系人',
    //   label: '联系人',
    //   componentType: 'Input',
    //   allowClear: true,
    //   md: 6,
    //   sm: 24,
    //   whetherSenior: false,
    // },
    // {
    //   name: 'phoneMobile',
    //   placeholder: '联系电话',
    //   label: '联系电话',
    //   componentType: 'Input',
    //   allowClear: true,
    //   md: 6,
    //   sm: 24,
    //   whetherSenior: false,
    // },
    // {
    //   name: 'bankName',
    //   placeholder: '开户行名称',
    //   label: '开户行名称',
    //   componentType: 'Input',
    //   allowClear: true,
    //   md: 4,
    //   sm: 24,
    //   whetherSenior: false,
    // },
  ];
};

/** 物料列表搜索 */
const getMaterialSearchList = (loadInfo: Record<string, any>): ManageCommonAPI.ISearchList => {
  return [
    {
      name: 'fullName',
      placeholder: '物料名称',
      label: '物料名称',
      componentType: 'Input',
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'specInfo',
      placeholder: '规格参数',
      label: '规格参数',
      componentType: 'Input',
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'paramsInfo',
      placeholder: '物料简介',
      label: '物料简介',
      componentType: 'Input',
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'state',
      placeholder: '物料状态',
      label: '物料状态',
      componentType: 'Select',
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: false,
      dataSource: [
        {
          value: '0',
          name: '起草',
        },
        {
          value: '1',
          name: '审核中',
        },
        {
          value: '2',
          name: '有效',
        },
        {
          value: '3',
          name: '作废',
        },
      ],
    },
  ];
};

export { getSourceSearchList, getTempalSearchList, getSubjectSearchList, getMaterialSearchList };
